package 多线程.Threadpool;

import java.util.concurrent.*;

/**
 * @ClassName a
 * @since: 2023/9/13 15:13
 * @auth: kirito
 * @description:
 **/

public class ThreadPoolDemo2 {

    public static void main(String[] args) throws Exception{
        //1.创建线程池
        ExecutorService pool = new ThreadPoolExecutor(
                3,
                5,
                8,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        //2. 给任务线程池处理
        Future f1 = pool.submit(new MyCallable(100));
        Future f2 = pool.submit(new MyCallable(200));
        Future f3 = pool.submit(new MyCallable(300));
        Future f4 = pool.submit(new MyCallable(400));
        Future f5 = pool.submit(new MyCallable(500));

        System.out.println(f1.get());
        System.out.println(f2.get());
        System.out.println(f3.get());
        System.out.println(f4.get());
        System.out.println(f5.get());
    }
}
